from langchain.output_parsers import CommaSeparatedListOutputParser
from langchain_ollama import ChatOllama
from langchain_core.prompts import ChatPromptTemplate


messages = [
    (
        "system",
        "只需要给出列表内容，保证格式正确，不需要其他任何内容。"
    ),
    (
        "human",
        "给我一个关于{topic}的列表。"
    ),
]

prompt = ChatPromptTemplate.from_messages(messages)

output_parser = CommaSeparatedListOutputParser()


llm = ChatOllama(
    model="llama3.1",
    temperature=0.5,
)

chain = prompt | llm | output_parser
result = chain.invoke({"topic": "五个心情"})
print(result,'||',type(result))
